#include<iostream>
#include<map>
#include<string>

using namespace std;

int main(){

	freopen("input.txt","r",stdin);
	string s1,s2,s3,s4;
	cin>>s1>>s2>>s3>>s4;

	map<char,int> m1;
	string m2[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
	map<char,int> m3={
		{'0',0},
		{'1',1},{'2',2},{'3',3},{'4',4},{'5',5},
		{'6',6},{'7',7},{'8',8},{'9',9},{'A',10},
		{'B',11},{'C',12},{'D',13},{'E',14},{'F',15},
		{'G',16},{'H',17},{'I',18},{'G',19},{'K',20},
		{'L',21},{'M',22},{'N',23}
	};

	for(int i=0;i<s1.length();i++){
		m1[s1[i]]++;
	}
	int first=0,second=0;
	for(int i=0;i<s2.length();i++){
		if(s1[i]==s2[i]&&m1[s2[i]]!=0&&(!first||!second)){
			if(!first&&s2[i]<='G'&&s2[i]>='A'){
				cout<<m2[m3[s2[i]]-10];
				first=1;
			}
			else if(first&&!second&&(s2[i]<='9'&&s2[i]>='0'||(s2[i]<='N'&&s2[i]>='A'))){
				m3[s2[i]]>=10?cout<<" "<<m3[s2[i]]<<":":cout<<" 0"<<m3[s2[i]]<<":";
				second=1;
			}
		}
	}
	for(int i=0;i<s3.length();i++){
		if(s3[i]==s4[i]&&((s3[i]>='a'&&s3[i]<='z')||(s3[i]<='Z'&&s3[i]>='A'))){
			if(i<60)
				i>=10?cout<<i<<endl:cout<<"0"<<i<<endl;
			break;
		}
	}
	return 0;

}